from Data_Process import *

handler = DataProcess()

# 给出文档路径
filename = "./data/item_profile3.txt"
outfilename = "./data/goods_ekg.json"
inputs = open(filename, 'r', encoding='UTF-8')
outputs = open(outfilename, 'w', encoding='utf8')

for line in inputs:
    line1 = line.split(',', 3)
    goods_name = handler.get_goods_name(line1[0])
    if not goods_name:
        continue
    crowd = handler.get_crowd(line1[0])
    brand_sy = handler.get_brand_synonym(line1[1])
    stc = line1[-1].split("$")
    if len(stc) == 2:
        stc.append("")
    scene_sy, theme_sy, category_sy = handler.get_stc_synonym(line1[-1])
    dict = {
        "goods_name": goods_name,
        "crowd": crowd,
        "brand": line1[1],
        "brand_synonym": brand_sy,
        "scene": stc[0],
        "scene_synonym": scene_sy,
        "theme": stc[1],
        "theme_synonym": theme_sy,
        "category": stc[2].strip('\n'),
        "category_synonym": category_sy
    }
    print(dict)
    outputs.write(json.dumps(dict, ensure_ascii=False))
    outputs.write('\n')


